package org.hbs.blog.code.dao.impl;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.hbs.blog.code.dao.IBlogDao;
import org.hbs.blog.code.entity.Blog;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

@Repository("blogDao")
public class BlogDao extends SqlSessionDaoSupport implements IBlogDao {

	@Resource(name = "sqlSessionFactory")
	private SqlSessionFactory sqlSessionFactory;

	@PostConstruct
	public void initializeSqlSessionFactory() {
		super.setSqlSessionFactory(sqlSessionFactory);
	}
	/*
	 * (non-Javadoc)
	 * @see org.hbs.blog.code.dao.IBlogDao#insertBlog(org.hbs.blog.code.entity.Blog)
	 */
	public Blog insertBlog(Blog blog) {
		super.getSqlSession().insert("insertBlog", blog);
		return blog;
	}
	/*
	 * (non-Javadoc)
	 * @see org.hbs.blog.code.dao.IBlogDao#selectAllBlog()
	 */
	public List<Blog> selectAllBlog() {
		return super.getSqlSession().selectList("selectAllBlog");
	}
	/*
	 * (non-Javadoc)
	 * @see org.hbs.blog.code.dao.IBlogDao#selectBlogByID(java.lang.String)
	 */
	public Blog selectBlogByID(String blogID) {
		return super.getSqlSession().selectOne("selectBlogByID", blogID);
	}
	/*
	 * (non-Javadoc)
	 * @see org.hbs.blog.code.dao.IBlogDao#deleteBlogByID(java.lang.String)
	 */
	public void deleteBlogByID(String blogID) {
		super.getSqlSession().delete("deleteBlogByID", blogID);
	}
	/*
	 * (non-Javadoc)
	 * @see org.hbs.blog.code.dao.IBlogDao#updateBlogByID(org.hbs.blog.code.entity.Blog)
	 */
	public Blog updateBlogByID(Blog blog) {
		super.getSqlSession().update("updateBlogByID", blog);
		return blog;
	}

}
